﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class ClientCommentInformation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindFeedback();
            }
        }

        private void BindFeedback()
        {
            ApplicationService service = new ApplicationService();
            ApplicationForm form = service.GetApplicationFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            if (!form.UserReference.IsLoaded)
            {
                form.UserReference.Load();
            }
            if (!form.FeedbackReference.IsLoaded)
            {
                form.FeedbackReference.Load();
            }
            //if (!form.RequisitionFormReference.IsLoaded)
            //{
            //    form.RequisitionFormReference.Load();
            //}
            clientNameLabel.Text = form.User.FullName;
            connectPersonLabel.Text = form.User.ContactPerson;
            phoneLabel.Text = form.User.UserPhone;
            receiveProductLabel.Text = "收货无误";
            clientReceivetimeLabel.Text = form.ClientReceiveDateTime.HasValue ? Convert.ToDateTime(form.ClientReceiveDateTime).ToString("yyyy-MM-dd") : "";
            //requisitionTimeLabel.Text = form.RequisitionForm.RequisitionDatetime != null ? Convert.ToDateTime(form.RequisitionForm.RequisitionDatetime).ToString("yyyy-MM-dd") : "";
            requisitionTimeLabel.Text = form.SendBackDateTime.HasValue ? form.SendBackDateTime.Value.ToString("yyyy-MM-dd") : "";
            if (form.Feedback != null)
            {
                productQualitySatifyLabel.Text = form.Feedback.ProductQuality;
                productQualityClientcommentLabel.Text = form.Feedback.ProductQualityComment;
                produectFunctionsatifyLabel.Text = form.Feedback.ProductFunction;
                produectFunctionCommentLabel.Text = form.Feedback.ProductFunctionComment;
                maintainQualitySatisfyLabel.Text = form.Feedback.MaintainQuality;
                maintainQualityCommentLabel.Text = form.Feedback.MaintainQualityComment;
                maintainPeriodSatisfyLabel.Text = form.Feedback.MaintainPeriod;
                maintainPeriodCommentLabel.Text = form.Feedback.MaintainPeriodComment;
                serviceSatisfyLabel.Text = form.Feedback.ServiceResponse;
                serviceCommentLabel.Text = form.Feedback.ServiceResponseComment;
                distributeSatifyLabel.Text = form.Feedback.DistributeService;
                distributeCommentLabel.Text = form.Feedback.DistributeServiceComment;
                costSatisfyLabel.Text = form.Feedback.Cost;
                costCommentLabel.Text = form.Feedback.CostComment;
                websiteSatisfyLabel.Text = form.Feedback.WebsiteEvaluate;
                websiteCommentLabel.Text = form.Feedback.WebsiteEvaluateComment;
            }
        }

        protected void submitLinkButton_Click(object sender, EventArgs e)
        {
            ApplicationService service = new ApplicationService();
            ApplicationForm form = service.GetApplicationFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            if (!form.FeedbackReference.IsLoaded)
            {
                form.FeedbackReference.Load();
            }
            form.Feedback.ProductQualityRemark = productQualityRemarkTextBox.Text;
            form.Feedback.ProductFunctionRemark = produectFunctionRemarkTextBox.Text;
            form.Feedback.MaintainQualityRemark = maintainQualityRemarkTextBox.Text;
            form.Feedback.MaintainPeriodRemark = maintainPeriodRemarkTextBox.Text;
            form.Feedback.ServiceResponseRemark = serviceRemarkText.Text;
            form.Feedback.DistributeServiceRemark = distributeRemarkTextBox.Text;
            form.Feedback.CostRemark = costRemarkTextBox.Text;
            form.Feedback.WebsiteEvaluateRemark = websiteRemarkLabel.Text;

            service.UpdateApplication(form);
        }
    }
}
